package com.atguigu.tingshu.payment.api;

import com.atguigu.tingshu.common.login.EnableLoginAuth;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.payment.service.WxPayService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "微信支付接口")
@RestController
@RequestMapping("api/payment/wxPay")
@Slf4j
public class WxPayApiController {

    @Autowired
    private WxPayService wxPayService;

    @EnableLoginAuth
    @PostMapping("/createJsapi/{itemType}/{orderNo}")
    public Result<Map<String, String>> createJsapi(@PathVariable String itemType, @PathVariable String orderNo) {
        Map<String, String> map = this.wxPayService.createJsapi(itemType, orderNo);
        return Result.ok(map);
    }

    @PostMapping("/notify")
    public Map<String, String> notifyFunction(HttpServletRequest request) {
        return this.wxPayService.notifyFunction(request);
    }

    @GetMapping("/queryPayStatus/{orderNo}")
    public Result<Boolean> queryPayStatus(@PathVariable String orderNo) {
        Boolean flag = this.wxPayService.queryPayStatus(orderNo);
        return Result.ok(flag);
    }
}
